<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html lang="zh-cn">

<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge,chrome=1">
<title>Chauncy宿舍管理系统登录页</title>
<meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />

<link rel="stylesheet" href="css/tabris.css">
<link rel="stylesheet" href="css/lib.css">
<link rel="stylesheet" href="layui/css/layui.css" />
<script type="text/javascript" src="layui/layui.js" ></script>
<script type="text/javascript" src="jquery-3.3.1/jquery-3.3.1.js" ></script>
<script type="text/javascript" src="jquery-3.3.1/jquery-3.3.1.min.js" ></script>


</head>
<style>
	.box-hide-state{
		display: none;
	}
</style>
<body>
<div class="bg0 pa">
	<div class="bg1"></div>
</div>
<div class="hx-box pa">
	<ul class="pr">
		<li class="hx-k1 pa0">
			<span></span>
		</li>
		<li class="hx-k2 pa0">
			<span></span>
		</li>
		<li class="hx-k3 pa0">
			<span></span>
		</li>
	</ul>
</div>
<div class="layui-container" style="position: relative;top: 5%;">
	<div class="layui-row" style="text-align:center;">
		<fieldset class=" layui-elem-field layui-field-title">
			<legend style="color: #FFFFFF;">欢迎使用Chauncy宿舍管理系统</legend>
		</fieldset>
	</div>
	<div class="layui-row" style="margin-top: 20%;">
		<div class="layui-col-md2 layui-col-lg-offset4" style="text-align: center;">
			<button class="layui-btn layui-btn-lg layui-btn-radius layui-bg-green layui-btn-normal" id="studentBtn" onclick="openLoginPage(0)">Student Login</button>
		</div>
		<div class="layui-col-md2" style="text-align: center;">
			<button class="layui-btn layui-btn-lg layui-btn-radius layui-btn-normal layui-bg-green" id="managerBtn" onclick="openLoginPage(1)">ManagerLogin</button>
		</div>
	</div>
	
	<div class="box box-hide-state stuLogin layui-anim-up" id="stuLoginPage" ">
		<header>
			<h2><b>Student&nbsp;Login</b></h2>
			<label class="right-close-icon" onclick="closeLoginPage(0)">
				<i class="layui-icon layui-icon-close"></i>
			</label>
		</header>
		<!-- action="userLoginServlet"  -->
		<form class="layui-form" >
			<div class="layui-form-item "> 
				<label class="beg-login-icon">
					<i class="layui-icon layui-icon-username"></i>  
				</label>
					<input id="username" type="text" name="userName"  lay-verify="required"  autocomplete="off" placeholder="请输入学号" class="layui-input input">
			</div>
			<div class="layui-form-item ">
				<label class="beg-login-icon">
				<i class="layui-icon layui-icon-password"></i>
			</label>
				<input id="password" type="password" name="password"  lay-verify="required"  autocomplete="off" placeholder="请输入密码" class="layui-input input">
			</div>
			 <div class="layui-form-item ">
					<div class="right-text">
						
					</div>
  			</div>
			<div class="layui-form-item">
    			<div class="layui-input-block">
    				<button class="layui-btn" lay-submit lay-filter="userSubmit">立即提交</button>
      				<button type="reset" class="layui-btn layui-btn-primary">重置</button>
    			</div>
 			</div>
		</form>
	</div>
	
	<div class="box stuLogin box-hide-state layui-anim-up" id="managerLoginPage">
		<header class="header">
			<h2><b>Manager Login</b></h2>
			<label class="right-close-icon" onclick="closeLoginPage(1)">
				<i class="layui-icon layui-icon-close"></i>
			</label>
		</header>
		<form class="layui-form">
			<div class="layui-form-item "> 
				<label class="beg-login-icon">
					<i class="layui-icon layui-icon-user"></i>  
				</label>
					<input id="managerName" type="text" name="managerName" lay-verfy="required" autocomplete="off" placeholder="请输入登录名/工号" class="layui-input input">
			</div>
			<div class="layui-form-item ">
				<label class="beg-login-icon">
				<i class="layui-icon layui-icon-password"></i>
			</label>
				<input id="managerPassword" type="password" name="managerPassword" lay-verify="required" autocomplete="off" placeholder="请输入密码" class="layui-input input">
			</div>
			 <div class="layui-form-item ">
					<div class="right-text">
						
					</div>
  			</div>
			<div class="layui-form-item">
    			<div class="layui-input-block">
    				<button class="layui-btn" lay-submit lay-filter="managerSubmit">立即提交</button>
      				<button type="reset" class="layui-btn layui-btn-primary">重置</button>
    			</div>
 			</div>
		</form>
	</div>
</div>
</body>
<script  type="text/javascript">	
	layui.use(['form','layer'],function(){
		var form = layui.form,
		layer = layui.layer;
		//监听学生用户提交
		form.on('submit(userSubmit)',function(data){
			$.ajax({
				type:"post",
				url:"userLoginServlet",
				async:true,
				data:{
					userName:data.field.userName,
					password:data.field.password
				},
				success : function(data){
				console.log(data);
						if(data == "userExist"){
							document.write("<form action='userLoginServlet?userFlag=1' method='post' name='formx1' style='display:none'></form>");
							document.formx1.submit();
						}
						if(data == "userDormInfoExist"){
							//用户存在 住宿信息存在
							document.write("<form action='userLoginServlet?userFlag=1' method='post' name='formx1' style='display:none'></form>");
							document.formx1.submit();
						}
						if(data == "userDormInfoNotExist"){
							//用户存在 住宿信息存在
							document.write("<form action='userLoginServlet?userFlag=2' method='post' name='formx1' style='display:none'></form>");
							document.formx1.submit();
						}
						 if(data == "userNotExist"){
						 	layer.msg("用户名或密码错误");
						}
				}
		});
			return false;
		});
		form.on('submit(managerSubmit)',function(val){
			$.ajax({
			type:"post",
			url:"managerLoginServlet",
			async:true,
			data:{
				managerName:val.field.managerName,
				managerPassword:val.field.managerPassword
			},
			success : function(data){
				if(data == "managerExist"){
					//managerInfo存在
					document.write("<form action='managerLoginServlet?managerFlag=1' method='post' name='formx2' style='display:none'></form>");
					document.formx2.submit();
				}
				if(data == "managerNotExist"){
					layer.msg("用户名或密码错误");
				}
			}
		});	
			return false;
		});
		
	});
	function managerLogin(obj){
		$.ajax({
			type:"post",
			url:"",
			async:true,
			data:{managerInfo:obj},
			success : function(data){
				if(data == 'error'){
					
				}
			},
			error : function(){
				
			}
		});
	}
	



	function openLoginPage(flag){
		if(flag == 0){
			document.getElementById("stuLoginPage").classList.remove("box-hide-state");
			document.getElementById("managerLoginPage").classList.add("box-hide-state");		
		}else if(flag == 1){
			document.getElementById("managerLoginPage").classList.remove("box-hide-state");
			document.getElementById("stuLoginPage").classList.add("box-hide-state");
		}
	};
	function closeLoginPage(flag){
		if(flag == 0){
			document.getElementById("stuLoginPage").classList.add("box-hide-state");
		}else if(flag == 1){
			document.getElementById("managerLoginPage").classList.add("box-hide-state");
		}
	}

</script>


</html>
